package display
{
	import display.data.CTextFieldType;
	
	import skinfactory.SkinButton;

	public class CButton extends SkinButton
	{
		private var _title: String;
		
		private var tfTitle: CTextField;
		
		public function CButton( title: String, tag: String )
		{
			super( tag );
			_title = title;
			this.init();
		}
		private function init(): void
		{
			tfTitle = new CTextField( CTextFieldType.BUTTON_TITLE );
			tfTitle.defaultTextFormat = CTextFormat.getInstance().btnTitle;
			tfTitle.text = _title;
			
			if( btnArea.width < tfTitle.width )
			{
				this.width = tfTitle.width + 20;
			}
			
			this.setPosition();
			this.initChild();
		}
		override protected function setPosition():void
		{
			if( tfTitle != null )
			{
				tfTitle.x = int( btnArea.width - ( btnArea.width + tfTitle.width ) / 2 );
				tfTitle.y = int( btnArea.height - ( btnArea.height + tfTitle.height ) / 2 );
			}
		}
		private function initChild(): void
		{
			this.addChild( tfTitle );
		}
		override public function set buttonMode(value:Boolean):void
		{
			super.buttonMode = value;
			if( value )
				tfTitle.alpha = 1;				
			else
				tfTitle.alpha = 0.5;
		}
	}
}